# 3.24 Button Control Fan ## 3.24.1 Overview In this experiment, we program to control the fan by a button. ## 3.24.2 Test Code ### 3.24.2.1 Code Flow ![6-24-2-1](./media/6-24-2-1.png) ### 3.24.2.2 Build Code There are two ways to upload the code: directly open the code file we provide; or manually build blocks. **Directly open the code file we provide:** 1. Click ![](./media/j68.png) and choose `Load from your computer` ![](./media/j67.png) 2. We have already downloaded the codes on computer desktop, so open the file and choose `3-24-electricFan.sb3` **Manually build blocks:** 1. Build the two basic blocks: ![6-1-4-1-1](./media/6-1-4-1-1.png) 2. Declare a variable and name to *item*, and assign the analog value read by ADKey to it. ![](./media/6-24-2-2-1.png) 3. Add a ![j25](./media/j25.png) to determine the value of *item*. When item > 3500 (the red button is pressed), the fan stops. When item > 2000 & item < 3000 (the yellow button is pressed), the fan rotates. 3. At last, add a delay of 0.3s. ![6-24](./media/6-24-2-2-2.png) **Complete Test Code** ![6-24](./media/6-24-2-2-3.png) ### 3.24.2.3 Test Result After uploading code, when we press the yellow button, the fan will turn on. When we press the red button, the fan stops working.